<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--    <link rel="stylesheet" href="../../static/lib/layui-v2.6.3/css/layui.css" media="all">-->
    <link th:href="@{../static/lib/layui-v2.6.3/css/layui.css}" rel="stylesheet">
<!--    <link rel="stylesheet" href="../../css/public.css" media="all">-->
    <link th:href="@{../static/css/public.css}" rel="stylesheet">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form layuimini-form" lay-filter="editFormFilter">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户数据</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入参数编码" value="" class="layui-input">
<!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label required">性别</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="radio" name="sex" value="男" title="男" checked="">-->
<!--            <input type="radio" name="sex" value="女" title="女">-->
<!--        </div>-->

<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label required">部门编号</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="text" name="paramName" lay-verify="required" lay-reqtext="部门不能为空" placeholder="请输入参数名称" value="" class="layui-input">-->
<!--        </div>-->
<!--    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label">部门编号</label>
        <div class="layui-input-block">
            <input type="text" name="dep"  lay-verify="required" placeholder="请输入部门编号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email"  lay-verify="required" placeholder="请输入邮箱" value="" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认更新</button>
        </div>
    </div>
</form>
<script src="../static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<!-- 子页面 (child.html) -->
<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        var queryParams = new URLSearchParams(window.location.search);
        var id = queryParams.get('id');
        // var paramCode = queryParams.get('paramCode');
        // var paramValue = queryParams.get('paramValue');
        console.log(id); // 显示传递的参数值
        // $("#paramCode").val(paramCode);
        // $('[name="paramValue"]').val(paramValue);
        layer.load(1);
        $.get('/getUserById',{id:id}, function(a){
            console.log(a);
            if(a.code == 200){
                user = a.data;
                // layer.msg('登录成功 - 欢迎用户: ' + user.paramCode , {icon: 1});
                layer.closeAll();
                $('[name="dep"]').val(user.dep);
                $('[name="email"]').val(user.email);
                $("#name").val(user.name);

            }else {
                layer.closeAll('loading');
                layer.msg('登录失败'+a.message, {icon: 2});
                return false;
            }
        }).fail(function(){

            layer.msg('请求失败，请重试', {icon: 2});
            return false;
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '添加信息：'
            });
            //     // 发送打卡请求
                $.post('/update-user',{id: id, name: data.field.name , dep: data.field.dep,email: data.field.email } , function(res){
                    layer.closeAll();
                    if(res) {  // 直接判断Boolean返回值
                        layer.msg('添加成功 - 用户: ' + data.field.paramCode , {icon: 1});
                        // layer.close(index);// 关闭弹出层
                    } else {
                        layer.msg('添加失败', {icon: 2});
                        // layer.close(index);// 关闭弹出层
                    }
                }).fail(function(){
                    layer.closeAll();
                    layer.msg('请求失败，请重试', {icon: 2});
                    layer.close(index);// 关闭弹出层
                });

            // function () {
            // if(parent.submitFormCallback){
            //     parent.submitFormCallback(data.field);// 关闭弹出层
            //     layer.close(index);// 关闭弹出层
            // } else {
            //     layer.msg('通信异常，请刷新重试', {icon: 2});
            //     layer.close(index);// 关闭弹出层
            // }
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
             // }

            return false;
        });
        });
</script>
</body>
</html>